package main

import (
	"context"
	"encoding/json"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/risk"
	risk2 "git.900sui.cn/kc/rpcinterface/interface/risk"
	"git.900sui.cn/kc/rpcinterface/interface/task/cards"
	"github.com/streadway/amqp"
)
/******************************************
@Description:风控 卡项上下架统计
交换机=shop.items
@Time : 2020/11/13 9:02
@Author :lixiaojun
*******************************************/

func main()  {
	rpcRisk:=new(risk.BusBasicMonth).Init()
	defer rpcRisk.Close()
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("cards.log.upDown"))
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("cards.queue.upDown"), func(msg amqp.Delivery) {
		var itemData cards.ShopItems
		err := json.Unmarshal( msg.Body, &itemData )
		if err != nil{
			return
		}
		shopId:=itemData.ShopId
		var reply bool
		if err:=rpcRisk.StatisticsCardProductUnderRateRpc(context.Background(),&risk2.ArgsStatisticsCardProductUnderRate{ShopId: shopId},&reply);err!=nil{
			utils.Logerr.Printf("统计卡项上下架任务错误 shopId:%d  err: %s",shopId, err.Error())
		}
		utils.Logerr.Printf("统计卡项任务成功，shopId:%s", shopId)
	})

	if err != nil {
		utils.Logerr.Printf("统计卡项上下架任务错误 err: %s", err.Error())
	}
}
